const questionList = JSON.parse(localStorage.getItem('questionList'))
const user = JSON.parse(localStorage.getItem('exam-data'))


// 题量
const num = questionList.length
// 总分
const score = questionList.length * 2

// 渲染表格
const tbody = document.querySelector('tbody')
tbody.innerHTML = ''
user.forEach((item, index) => {

  // 解构user
  const { name, account: ID, historicalScore: [firstScore = 0, secondScore = 0, thirdScore = 0] } = item

  // 判断是否已考试
  let status = '缺考'
  status = firstScore === 0 && secondScore === 0 && thirdScore === 0 ? '缺考' : '已考'

  tbody.innerHTML += `
    <tr>
      <th>${index + 1}</th>
      <th>${ID}</th>
      <th>${name}</th>
      <th>当代大学生国家安全教育</th>
      <th>04-12 - 11-30</th>
      <th>${num}</th>
      <th>${score}.0</th>
      <th class="red">${status}</th>
      <th>${firstScore}.0</th>
      <th>${secondScore}.0</th>
      <th>${thirdScore}.0</th>
    </tr>
  `
  // 高亮显示缺考
  const red = document.querySelectorAll('.red')
  red.forEach(item => {
    item.style.color = item.innerHTML === '缺考' ? 'red' : 'black'
  })
})

